MAINLIB =$(HOME)/csr-repository/lib/
#MAININC =$HOME/csr-repository/include/
CFLAGS_COMMON=-I$(HOME)/csr-repository/include -I$(HOME)/csr-repository/include
# FLAGS for opencv
# -fPIC necessary to allow proper construction of shared library
LDFLAGS_COMMON = -lstdc++ -lwiringPi



BUILD_TYPE=debug
#BUILD_TYPE=release

ifeq ($(BUILD_TYPE), debug)
	CFLAGS = -g $(CFLAGS_COMMON)
    LDFLAGS = -g $(LDFLAGS_COMMON)
endif
ifeq ($(BUILD_TYPE), release)
	# -O3 tells the compiler to optimize which takes more time, however the code is about 50% faster
	CFLAGS = $(CFLAGS_COMMON) -O3
    LDFLAGS = $(LDFLAGS_COMMON)
endif

TARGETS= $(MAINLIB)/libcsrnet.so

OFILES= swarmSocketServer.o swarmSocketClient.o Network.o robotFunctions.o

all: $(TARGETS)

swarmSocketServer.o: swarmSocketServer.cpp
	gcc -c swarmSocketServer.cpp $(CFLAGS)

swarmSocketClient.o: swarmSocketClient.cpp
	gcc -c swarmSocketClient.cpp $(CFLAGS)

socketTest.o: socketTest.cpp
	gcc -c socketTest.cpp $(CFLAGS)

Network.o: Network.cpp
	gcc -c Network.cpp $(CFLAGS)

robotFunctions.o: ../Algorithms/robotFunctions.cpp
	gcc -c ../Algorithms/robotFunctions.cpp $(CFLAGS)

$(MAINLIB)/libcsrnet.so: $(OFILES)
	gcc -shared -o $(MAINLIB)/libcsrnet.so $(LDFLAGS) $+

clean:	
	rm -f *.o
	rm -f *.d
